local chenzhu = fk.CreateSkill{
  name = "xiaobai__chenzhu"
}

Fk:loadTranslationTable{
  ["xiaobai__chenzhu"] = "沉诛",
  [":xiaobai__chenzhu"] = "出牌阶段限一次，你可以重铸至多两张牌，然后你令一名其他角色也可如此做，"..
                     "若你与其被重铸的牌花色均不同，则你可以使用一张【杀】。",
  ["#xiaobai__chenzhu-description"] = "沉诛：你可以重铸至多两张牌",
  ["#xiaobai__chenzhu-choose_other_player"] = "沉诛：选择一名其他角色，令其也可重铸至多两张牌",
  ["#xiaobai__chenzhu-other_choose_cards"] = "沉诛：你可以重铸至多两张牌",
  ["#xiaobai__chenzhu-use_slash"] = "沉诛：你可以使用一张【杀】",

  ["$xiaobai__chenzhu1"] = "职司不忠、奸党相扶,百姓愁劳，何以用治？",
  ["$xiaobai__chenzhu2"] = "王者受之于天，今上逆犯天地，吾等当断。",
}

chenzhu:addEffect("active", {
  name = "xiaobai__chenzhu",
  anim_type = "offensive",
  can_use = function (self, player)
    return player:usedSkillTimes(chenzhu.name, Player.HistoryPhase) == 0 and #player:getCardIds("he")>0 
  end,
  target_num = 0,
  min_card_num = 1,
  max_card_num = 2,
  prompt = "#xiaobai__chenzhu-description",
  card_filter = function (self, player, to_select, selected)
    return #selected <  2
  end,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = effect.from
    local cards1 = effect.cards
    local cards2 = {}
    room:recastCard(effect.cards, player, chenzhu.name)
    if player.dead then return end

    local target_all = table.filter(room:getOtherPlayers(player), function (p)
      return #p:getCardIds("he")>0
    end)
    local targets
    if #target_all > 0 then
      targets = room:askToChoosePlayers(player, {
        targets = target_all, 
        min_num = 1, 
        max_num =   1, 
        prompt = "#xiaobai__chenzhu-choose_other_player",
        skill_name = chenzhu.name,
        cancelable = false
      })
      if targets and #targets>0 then
        local target = targets[1]
        cards2 = room:askToCards(target,{
          min_num = 1,
          max_num = 2,
          include_equip = true,
          no_indicate = false,
          skill_name = chenzhu.name,
          prompt = "#xiaobai__chenzhu-other_choose_cards"
        })
        if #cards2 > 0 then
          room:recastCard(cards2, target, chenzhu.name)
        end
      end
    end
    if player.dead then return end

    local all_cards = {}   ---@type Card[]
    for _, value in ipairs(cards1) do
      table.insert(all_cards,Fk:getCardById(value))
    end
    if cards2 ~= nil and #cards2 > 0 then
      for _, value in ipairs(cards2) do
        table.insert(all_cards,Fk:getCardById(value))
      end
    end
    if #all_cards <2 then return end
    local suit_num = {}
    for index, value in ipairs(all_cards) do
      if value.suit ~= Card.NoSuit then
        if suit_num[value.suit] then
          return
        else
          suit_num[value.suit] = true
        end
      end
    end
    local use = player.room:askToUseCard(player, {
      pattern = "slash",
      skill_name = chenzhu.name,
      extra_data = {bypass_times = true},
      prompt = "#xiaobai__chenzhu-use_slash",
    })
    if use then
      room:useCard(use)
    end
  end
})

return chenzhu